package org.sbbs.tool;

public class SingleEntityExporter extends SbbsAbstractExporter {
	private String templateType = "single";

	protected void generateCore() {

		// generate sample-data.xml
		configureExporter("sbbs/" + templateType + "/dao/sample-data.ftl", "src/test/resources/{class-name}-sample-data.xml").start();

		// DAO Test
		configureExporter("sbbs/" + templateType + "/dao/dao-test.ftl", "src/test/java/{basepkg-name}/dao/{class-name}DaoTest.java").start();

		// DAO Interfaces
		configureExporter("sbbs/" + templateType + "/dao/dao.ftl", "src/main/java/{basepkg-name}/dao/{class-name}Dao.java").start();

		String daoFramework = getProperties().getProperty("daoframework");

		// DAO Implementation
		configureExporter("sbbs/" + templateType + "/dao/" + daoFramework + "/dao-impl.ftl",
				"src/main/java/{basepkg-name}/dao/" + daoFramework + "/{class-name}Dao" + getDaoFilename(daoFramework) + ".java").start();

		// Manager Test
		configureExporter("sbbs/" + templateType + "/service/manager-test.ftl", "src/test/java/{basepkg-name}/service/impl/{class-name}ManagerImplTest.java").start();

		// Manager Interface
		configureExporter("sbbs/" + templateType + "/service/manager.ftl", "src/main/java/{basepkg-name}/service/{class-name}Manager.java").start();

		// Manager Implementation
		configureExporter("sbbs/" + templateType + "/service/manager-impl.ftl", "src/main/java/{basepkg-name}/service/impl/{class-name}ManagerImpl.java").start();
	}

	protected void generateWeb() {
		String packaging = getProperties().getProperty("packaging");
		boolean webProject = packaging != null && packaging.equalsIgnoreCase("war");

		if (!webProject)
			return;

		// tests
		configureExporter("sbbs/" + templateType + "/web/struts/action-test.ftl", "src/test/java/{basepkg-name}/webapp/action/{class-name}PagedActionTest.java").start();
		configureExporter("sbbs/" + templateType + "/web/struts/action-test.ftl", "src/test/java/{basepkg-name}/webapp/action/{class-name}EditActionTest.java").start();

		// controllers
		configureExporter("sbbs/" + templateType + "/web/struts/action.ftl", "src/main/java/{basepkg-name}/webapp/action/{class-name}PagedAction.java").start();

		configureExporter("sbbs/" + templateType + "/web/struts/edit-action.ftl", "src/main/java/{basepkg-name}/webapp/action/{class-name}EditAction.java").start();

		// views

		configureExporter("sbbs/" + templateType + "/web/struts/list-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}List.jsp").start();

		configureExporter("sbbs/" + templateType + "/web/struts/form-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}Form.jsp").start();

		configureExporter("sbbs/" + templateType + "/web/struts/struts.ftl", "src/main/java/{basepkg-name}/webapp/struts_action_{class-name}.xml").start();

		// i18n
		configureExporter("sbbs/" + templateType + "/web/ApplicationResources.ftl", "src/main/java/{basepkg-name}/webapp/{class-name}-package.properties").start();

	}
}
